#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    vector<int> sortColors(vector<int>& nums)
    {
        int n = nums.size();
        int i = 0, left = -1, right = n;
        while (i < right)
        {
            if (nums[i] == 0) swap(nums[++left], nums[i++]);
            else if (nums[i] == 1) i++;
            else swap(nums[--right], nums[i]);
        }
        return nums;
    }
};

int main()
{
    Solution sol;
    vector<int> nums, ret;
    nums.push_back(0);
    nums.push_back(2);
    nums.push_back(2);
    nums.push_back(1);
    nums.push_back(2);
    nums.push_back(1);
    nums.push_back(0);
    nums.push_back(0);
    nums.push_back(2);
    nums.push_back(1);
    nums.push_back(2);

    ret = sol.sortColors(nums);

    for (auto e : ret)
    {
        cout << e << " ";
    }
    cout << endl;
    return 0;
}